
*********************************
** Load correct visits effects:
	estimates use output\causal_visits
		global veffectp = _b[Np]
		global veffecte = _b[Ne]
*********************************



*****************************************
** Load relevant dataset & keep libraries for which all three exist

use "$datapath\intermediate\collect_pdouble_staff.dta", clear
	
	gen id = 1 if raise=="Pe" 
	replace id = 2 if raise=="Pp"
	
	bys lno: gen Nlno = _N
	tab Nlno
	keep if Nlno==3
	distinct lno
	
*****************************************


*****************************************
** Keep libraries that solve to observed holding: 
	
	gen similar = (abs(Np-mNp)<.1 ) * (factor==10)
	egen SIMILAR = sum(similar), by(lno)
	tab SIMILAR if factor==10

	keep if SIMILAR==1
	
	
************************
** Drop libraries that solve to corners
	
	gen tag = mNp<1 | mNe<1
	egen TT = max(tag), by(lno)
	tab TT if raise=="Pe" & factor==10
	drop if TT==1
	

************************


***************************************************************
** Keep averages and create ratios:

	gen xc10 = CS if factor==10
	egen XC10 = mean (xc10), by(lno)	
	gen rCS = CS/XC10-1
	
	gsort lno factor raise
	gen rCS_ratio = rCS/rCS[_n-1] if raise=="Pp"
	
	collapse (mean) CS (p50) median_rCS_ratio = rCS_ratio, by(id factor raise)

		gen double x_CS = CS if factor==10
		egen double X_CS = mean(x_CS)
		gen r_CS = (CS-X_CS)/X_CS

	keep if factor==20

		gen xr_CS = r_CS if raise=="Pe"
		egen Xr_CS = mean(xr_CS)
		gen mean_rCS_ratio = r_CS/Xr_CS if raise=="Pp"
		
	su mean_rCS_ratio median_rCS_ratio
	
	
	
	
	
	
	
	
	
	